package com.example.libraryapp.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.example.libraryapp.R;


public class ExitDialog implements View.OnClickListener {

    private DiyDialog dialog;

    private TextView mTitle;

    private OnExitDialogListener mOnExitDialogListener;

    public ExitDialog(Context context, String title, OnExitDialogListener onExitDialogListener) {
        this.mOnExitDialogListener = onExitDialogListener;
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_exit, null);
        dialog = new DiyDialog(context, view);
        initView(view);
        if(!TextUtils.isEmpty(title)) {
            mTitle.setText(title);
        }
    }

    public ExitDialog(Context context, OnExitDialogListener onExitDialogListener) {
        this(context,null,onExitDialogListener);
    }

    public void setText(String text) {
        mTitle.setText(text);
    }

    private void initView(View view) {
        mTitle = view.findViewById(R.id.title);
        view.findViewById(R.id.cancel_btn).setOnClickListener(this);
        view.findViewById(R.id.commit_btn).setOnClickListener(this);
    }

    /**
     * Miss method
     */
    public void dismiss(){
        dialog.closeDiyDialog();
    }

    /**
     * Show method
     */
    public void show() {
        dialog.showDiyDialog();
    }

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.cancel_btn) {
            mOnExitDialogListener.cancel();
        }else {
            mOnExitDialogListener.sure();
        }
        dismiss();
    }

}
